package com.je180503.dao.util;

public class PageTool {
    private int totalRecordCount;//总记录数
    private int pageSize=5;//每页条数
    private int pageCount;//总页数
    private int currentPage=1;

    public PageTool(int totalRecordCount,int currentPage){
        setTotalRecordCount(totalRecordCount);
        setCurrentPage(currentPage);
    }

    public PageTool(int totalRecordCount,int currentPage,int pageSize){
        this.pageSize=pageSize;
        setTotalRecordCount(totalRecordCount);

        setCurrentPage(currentPage);
    }


    public int getTotalRecordCount() {
        return totalRecordCount;
    }
    public void setTotalRecordCount(int totalRecordCount) {

        if(totalRecordCount>0){

            this.totalRecordCount=totalRecordCount;


        }else{
            this.totalRecordCount=0;
        }
        setPageCountByRC();

    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;

        setTotalRecordCount(totalRecordCount);

        setCurrentPage(currentPage);



    }
    public int getPageCount() {
        return pageCount;
    }
    //��ҳ��
    public void setPageCountByRC() {
        if(this.totalRecordCount%this.pageSize==0){
            this.pageCount=this.totalRecordCount/this.pageSize;

        }else{

            this.pageCount=this.totalRecordCount/this.pageSize+1;

        }
    }
    public int getCurrentPage() {
        return currentPage;
    }
    //��ǰҳ
    public void setCurrentPage(int currentPage) {
        if(currentPage>this.pageCount){
            this.currentPage=this.pageCount;


        }else if(currentPage>0){
            this.currentPage=currentPage;


        }else{

            this.currentPage=1;
        }

    }

    /**
     * ��ò�ѯ���� limit x,n
     * @return
     */

    public int getStartRecord(){
        return this.pageSize*(this.currentPage-1);

    }


}

